package com.sky.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sky.domain.UmsMemberReceiveAddress;
import com.sky.service.UmsMemberReceiveAddressService;
import com.sky.mapper.UmsMemberReceiveAddressMapper;
import com.sky.utils.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【ums_member_receive_address(会员收货地址)】的数据库操作Service实现
* @createDate 2024-06-30 16:45:18
*/
@Service
public class UmsMemberReceiveAddressServiceImpl extends ServiceImpl<UmsMemberReceiveAddressMapper, UmsMemberReceiveAddress> implements UmsMemberReceiveAddressService{

    /**
     * 根据会员id查询会员的收货地址列表
     *
     * @param memberId
     * @return List<String>
     */
    @Override
    public List<String> getAddressByMemberId(Long memberId) {
        List<UmsMemberReceiveAddress> umsMemberReceiveAddresses = baseMapper.selectList(new LambdaQueryWrapper<UmsMemberReceiveAddress>()
                .eq(UmsMemberReceiveAddress::getMemberId, memberId));
        if (StringUtils.isNotEmpty(umsMemberReceiveAddresses)){
            return umsMemberReceiveAddresses.stream().map(data -> JSON.toJSONString(data)).toList();
        }
        return null;
    }

    /**
     * 根据id查询会员的收货地址列表
     *
     * @param addrId
     * @return List<String>
     */
    @Override
    public UmsMemberReceiveAddress getAddressById(Long addrId) {
        return baseMapper.selectById(addrId);
    }
}




